package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.service.EsIndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/esIndex")
@Api(value = "ES索引管理",tags = "ES索引管理")
public class EsIndexController {

    @Autowired
    private EsIndexService esIndexService;

    /**
     * 根据索引名称创建索引
     *
     * @return
     */
    @GetMapping("/create")
    @ApiOperation(value = "根据索引名称创建索引")
    public R<Boolean> indexCreate(String indexName) {
        return esIndexService.indexCreate(indexName);
    }

    /**
     * 根据索引名称、映射结构创建索引
     *
     * @return
     */
    @GetMapping("/createWithMapping")
    @ApiOperation(value = "根据索引名称、映射结构创建索引")
    public R<Boolean> indexCreateWithMapping(String indexName, String indexMapping) {

        return esIndexService.indexCreateWithMapping(indexName,indexMapping);
    }

    /**
     * 根据索引名称查询索引是否存在
     *
     * @return
     */
    @GetMapping("/indexExit")
    @ApiOperation(value = "根据索引名称查询索引是否存在")
    public R<Boolean> indexExit(String indexName) {

        return esIndexService.indexExit(indexName);
    }

    /**
     * 根据索引名称删除索引
     *
     * @return
     */
    @GetMapping("/indexDelete")
    @ApiOperation(value = "根据索引名称删除索引")
    public R<Boolean> indexDelete(String indexName) {

        return esIndexService.indexDelete(indexName);
    }

    /**
     * 根据索引名称获取mapping
     *
     * @return
     */
    @GetMapping("/indexGetMapping")
    @ApiOperation(value = "根据索引名称删除索引")
    public R<Map> indexGetMapping(String indexName) {

        return esIndexService.indexGetMapping(indexName);
    }
}
